package com.itheima.web.manager;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.domain.mongo.UserLocation;
import com.itheima.service.db.AdminService;
import com.itheima.service.db.UserInfoService;
import com.itheima.service.mongo.LocationService;
import com.itheima.service.mongo.UserLocationService;
import com.itheima.util.ResultInfo;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.data.mongodb.core.geo.GeoJsonPoint;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

@Component
public class UserManagementManager {

    @DubboReference
    private AdminService adminService;
    @DubboReference
    private LocationService locationService;
    //用户列表
    public ResultInfo findAll(Integer pageNum,Integer pageSize,String name) {
        //1.rpc调用service
        PageBeanVo pageBeanVo = adminService.findUserListByPage(pageNum, pageSize,name);
        List<UserInfo> userInfoList = (List<UserInfo>) pageBeanVo.getItems();
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
        page.setRecords(userInfoList);
        page.setTotal(pageBeanVo.getCounts());
        //2.返回
        return ResultInfo.success(page);
    }

    //搜索用户地理位置
    public Map findMap(Long userid) {
        //1.rpc调用service查询
        Map map = locationService.findLocation(userid);
        return map;
    }
}
